import 'dart:developer';

import 'package:flutter/services.dart';
// import 'package:kmxy_base/util/amap_location_util.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:kmxy_base/base/base_package.dart';
import 'package:kmxy_base_example/page/page_manage_package.dart';

void main() {
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(const Main());
}

class Main extends MainBase {
  const Main({Key? key}) : super(key: key);

  @override
  initData() async {
    // AMapLocationUtil.getInstance.initPrivacy();
    appFrontdesk();
    Net.init('', {});
  }

  @override
  ScreenDefault setDefaultWH() {
    return ScreenDefault(375, 812);
  }

  @override
  Widget setStartPage(BuildContext context) {
    return MainPage();
  }

  @override
  String setTitle() {
    return "kmxy_base";
  }

  @override
  Iterable<LocalizationsDelegate> localizationsDelegates() {
    return [
      const CupertinoLocalizationsDelegate(),
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
    ];
  }

  @override
  void appFrontdesk() async {
    super.appFrontdesk();
    // 获取剪切板里的内容跳转页面
    ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
    log(data?.text ?? '');
    String clipboardDataText = data?.text ?? '';
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    if (clipboardDataText.contains(packageInfo.packageName)) {
      Clipboard.setData(const ClipboardData(text: ''));
      Future.delayed(const Duration(milliseconds: 500), () {
        Event.eventBus.fire(Event(123, clipboardDataText));
      });
    }
  }
}
